<template>
  <view class="content">
    <view class="header">
      <image src="../../static/img/yh.png"></image>
    </view>

    <!-- <view class="list">
      <view class="list-call">
        <image class="img" src="/static/shilu-login/1.png"></image>
        <input class="sl-input" v-model="mobile" type="number" maxlength="11" placeholder="输入手机号" />
      </view>
      <view class="list-call">
        <image class="img" src="/static/shilu-login/2.png"></image>
        <input class="sl-input" v-model="password" type="text" maxlength="32" placeholder="输入密码" password="true" />
      </view>

    </view>
 -->
    <view class="button-login" hover-class="button-hover" @tap="bindLogin()">
      <text style="font-size: 40upx;">微信登录</text>
    </view>
	<!-- <button @getphonenumber='getuserinfo' open-type="getPhoneNumber" id="loginbtn" class="denglu" type="default"  >
		微信授权登录
	</button> -->
    <view class="agreenment">
      <!-- <navigator url="forget" open-type="navigate">忘记密码</navigator>
      <text>|</text> -->
      <!-- <navigator url="reg" open-type="navigate">注册账户</navigator> -->
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        mobile: '',
        password: '',
		openid:'',
		loginRes:{}
      };
    },
	 
    methods: {
      async bindLogin() {
		let _this =this
		uni.login({
			"provider": "weixin",
			"onlyAuthorize": true, // 微信登录仅请求授权认证
			success: (event)=>{
				//客户端成功获取授权临时票据（code）,向业务服务器发起登录请求。
				 this.$ajax('post','login/wechat',{code:event.code}).then(res=>{
					 uni.setStorage({//缓存配置信息
					 	key: 'token',  
					 	data: res.data.token
					 })
					 uni.navigateBack();
					 uni.setStorage({//缓存配置信息
					 	key: 'avatar',  
					 	data: avatar
					 })
					 uni.setStorage({//缓存配置信息
					 	key: 'userinfo',  
					 	data: res.data.data.userinfo
					 })
					 uni.setStorage({//缓存配置信息
					 	key: 'config',  
					 	data: res.data.data.config
					 })
					 setTimeout(()=>{
						 if(uni.getStorageSync("shareid")){
							 this.$ajax('post','share/user',{user_id:uni.getStorageSync("shareid")}) 
						 }
					 },200)
				 })
			},
			fail: function (err) {
		        // 登录授权失败
		        // err.code是错误码
		    }
		})
		
		
        return
        if(this.openid){
        	data.openid=this.openid;
        }
        let [err,res] =await this.$httpas.get('/api/user/login',data);
		
        if (!this.$httpas.errorCheck(err,res)) return;
        
        if(res.data.code === 1){
				if(res.data.data.userinfo.avatar){
						var str = res.data.data.userinfo.avatar;
						if(str.indexOf("data:image") != -1){
							var avatar='';
						}else{
							if(str.indexOf("http") != -1){
								avatar=res.data.data.userinfo.avatar;
							}else{
								avatar=this.configs.imgUrl+res.data.data.userinfo.avatar;
							}
						}
					}else{
						var avatar='';
					}
			uni.setStorage({//缓存配置信息
				key: 'avatar',  
				data: avatar
			})
			uni.setStorage({//缓存配置信息
				key: 'userinfo',  
				data: res.data.data.userinfo
			})
			uni.setStorage({//缓存配置信息
				key: 'config',  
				data: res.data.data.config
			})
        	uni.showModal({
        		title: '温馨提示',
        		content: res.data.msg,
        		showCancel: false,
        		confirmText: "确定",
        		success: function (res) {
        			if (res.confirm) {
        				uni.navigateBack();
        			} else if (res.cancel) {
        				
        			}
        		}
        	});
        }else{
			uni.showToast({ title: res.data.msg,icon:"none" });
        }

      }
    }
  }
</script>

<style>
	
  .content {
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .header {
    width: 161rpx;
    height: 161rpx;
    background: #01B750;
    box-shadow: 0rpx 12rpx 13rpx 0rpx #01B750;
    border-radius: 50%;
    margin-top: 30rpx;
    margin-left: auto;
    margin-right: auto;
  }

  .header image {
    width: 161rpx;
    height: 161rpx;
    border-radius: 50%;
  }

  .list {
    display: flex;
    flex-direction: column;
    padding-top: 50rpx;
    padding-left: 70rpx;
    padding-right: 70rpx;
  }

  .list-call {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    height: 100rpx;
    color: #333333;
    border-bottom: 0.5px solid #e2e2e2;
  }

  .list-call .img {
    width: 40rpx;
    height: 40rpx;
  }

  .list-call .sl-input {
    flex: 1;
    text-align: left;
    font-size: 32rpx;
    margin-left: 16rpx;
  }

  .button-login {
    color: #FFFFFF;
    font-size: 34rpx;
    width: 470rpx;
    height: 100rpx;
    background: linear-gradient(-90deg, #01B750, #01B750);
    box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.2);
    border-radius: 50rpx;
    line-height: 100rpx;
    text-align: center;
    margin-left: auto;
    margin-right: auto;
    margin-top: 100rpx;
  }

  .button-hover {
    background: linear-gradient(-90deg, #01B750, #01B750);
  }

  .agreenment {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    font-size: 30rpx;
    margin-top: 80rpx;
    color: #FFA800;
    text-align: center;
    height: 40rpx;
    line-height: 40rpx;
  }

  .agreenment text {
    font-size: 24rpx;
    margin-left: 15rpx;
    margin-right: 15rpx;
  }
</style>
